package org.telegram.bot.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.telegram.bot.domain.BotGroup;
import org.telegram.bot.service.IBotGroupService;

import jakarta.servlet.http.HttpServletResponse;

import java.util.List;

/**
 * 群组Controller
 *
 * @author wyx
 * @date 2023-08-17
 */
@RestController
@RequestMapping("/bot/group")
@Slf4j
public class BotGroupController extends BaseController
{
    @Autowired
    private IBotGroupService botGroupService;

    /**
     * 查询群组列表
     */
    @PreAuthorize("@ss.hasPermi('bot:group:list')")
    @GetMapping("/list")
    public TableDataInfo list(BotGroup botGroup)
    {
        startPage();
        List<BotGroup> list = botGroupService.selectBotGroupList(botGroup);
        return getDataTable(list);
    }
    
    /**
     * 简单列表
     */
    @GetMapping("/list/simple")
    public AjaxResult selectSimpleList(@RequestParam(value = "filter",required = false) String filter)
    {
        List<BotGroup> list;
        if(StringUtils.isEmpty(filter)){
            list = botGroupService.selectSimpleList();
        }else{
            list = botGroupService.selectSimpleList(false);
        }
       return AjaxResult.success(list);
    }
    
    /**
     * 导出群组列表
     */
    @PreAuthorize("@ss.hasPermi('bot:group:export')")
    @Log(title = "群组", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BotGroup botGroup)
    {
        List<BotGroup> list = botGroupService.selectBotGroupList(botGroup);
        ExcelUtil<BotGroup> util = new ExcelUtil<BotGroup>(BotGroup.class);
        util.exportExcel(response, list, "群组数据");
    }

    /**
     * 获取群组详细信息
     */
    @PreAuthorize("@ss.hasPermi('bot:group:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(botGroupService.selectBotGroupById(id));
    }

    /**
     * 新增群组
     */
    @PreAuthorize("@ss.hasPermi('bot:group:add')")
    @Log(title = "群组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BotGroup botGroup)
    {
        return toAjax(botGroupService.insertBotGroup(botGroup));
    }

    /**
     * 修改群组
     */
    @PreAuthorize("@ss.hasPermi('bot:group:edit')")
    @Log(title = "群组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BotGroup botGroup)
    {
        return toAjax(botGroupService.updateBotGroup(botGroup));
    }

    /**
     * 删除群组
     */
    @PreAuthorize("@ss.hasPermi('bot:group:remove')")
    @Log(title = "群组", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(botGroupService.deleteBotGroupByIds(ids));
    }
}
